#include <stdio.h>
#include <string.h>
#include <math.h>

int zhi[2002];
int zcnt[2002];

bool iszhi(int a)
{
    int i , to;    
    if (a==2) return true;
    if (a%2 == 0) return false;
    to = (int)sqrt(a);
    for (i=3; i<=to; i+=2)
    	if (a%i == 0) return false;
   	return true;
}    

void predo()
{
    int i, j, a, b;
    zhi[1] = 2;
    zhi[2] = 3;
    zhi[0] = 2;
    i = 1;
    while (zhi[zhi[0]] <= 10015)
    {
        a = 6*i - 1;
        b = 6*i + 1;
        if (iszhi(a)) zhi[ ++ zhi[0] ] = a;
        if (iszhi(b)) zhi[ ++ zhi[0] ] = b;
        i++;
    }
//    printf("the last is %d\n", zhi[0]);
}


void predo2()
{
    int i, now = 0;
    for (i=1; i<=zhi[0]; ++i)
    {
    	now += zhi[i];
    	zcnt[i] = now;
    }   	
//    printf("the last zcnt is %d\n", zcnt[ zhi[0]]);
}    

void checkout(int n)
{
    int i, j, to;
    int ans=0;
    bool nofind = true;
    i = 1;
    while (zhi[i] <= n )
    {
        for (j=0; j<i; ++j)
        {
            to = zcnt[i] - zcnt[j];
            if (to == n)
           	{
           	    nofind = false;
           	    to = i - j;
           	    ans ++;
//           	    break;
           	}    
        }    
        ++i;
    }   // end of check 
    if (nofind) printf("0\n");
    else   printf("%d\n", ans);
}    

int main()
{
    int n;
    predo();
    predo2();
 
    while (scanf("%d", &n), n)
    {
        checkout(n);
    }    
    return 0;
}    